/**
  ******************************************************************************
  * @file    i2c_master_poll.c
  * @author  MCD Application Team
  * @version V0.0.3
  * @date    Oct 2010
  * @brief   This file contains optimized drivers for I2C master
  ******************************************************************************
  * @copy
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
  */ 

#include "i2c_master_poll.h"

#define 	_EE_PAGE_LENGTH_	64

u8 EEPROM_read( u8* Buf, u16 Addr, u8 Lth) 
{
 cMemAddr = 1; SLAVE_ADDRESS =0x50; set_tout_ms(Lth);

  I2C_ReadRegister1(Addr,Lth,Buf);
	 if(!(tout()) )
{
	 I2C_Init();
			return 1;
		}
			return 0 ;
}

 

u8	EEPROM_write( u8* Buf, u16 Addr, u8 Lth)
{
	u8	Num;
	u8	Ret;

 cMemAddr = 1; SLAVE_ADDRESS =0x50;  
	Ret = 0;
	while(Lth){
		if(Addr&(_EE_PAGE_LENGTH_-1))
		{
			Num = _EE_PAGE_LENGTH_ - (Addr&(_EE_PAGE_LENGTH_-1));
		} else 
		{
			Num = _EE_PAGE_LENGTH_;
		}
		if(Num > Lth)
		{
			Num = Lth;
		}set_tout_ms(_EE_PAGE_LENGTH_);
		   I2C_WriteRegister1( Addr , Num, Buf );
		 if(!(tout()) )
{
	 I2C_Init();
			return 1;
		}
		Lth -= Num;
		Addr += Num;
		Buf+= Num;
		 I2C_SaveTime(3);	
		 
	}
 
	return Ret;
}


  
